package br.uvv.Dao;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.primefaces.model.SortOrder;

import br.uvv.Model.Ator;
import br.uvv.Util.DAOException;

@SuppressWarnings("unchecked")
public class AtorDAO extends DAO {

	private static final long serialVersionUID = 1644593689725160930L;

	public Ator selecionar(Long id) throws DAOException  {
		return (Ator) get(Ator.class, id);
	}
	
	public List<Ator> listar() throws DAOException{
		return (List<Ator>) list(Ator.class);
	}
	
	public void salvar(Ator atorInstance) throws DAOException {
		save(atorInstance, atorInstance.getId());
	}
	
	public void remover(Ator atorInstance) throws DAOException {
		delete(Ator.class, atorInstance.getId());
	}
	
	public List<Ator> listar(int first, int pageSize, String sortField, 
			SortOrder sortOrder, String nome) throws DAOException{
		Criterion[] filtros = { Restrictions.ilike("nome", "%" + nome + "%") };
		return (List<Ator>) listPaginator(first, pageSize, sortField, sortOrder, Ator.class, null, filtros);
	}
	
	public Integer count(String nome) throws DAOException {
		Criterion[] filtros = { Restrictions.ilike("nome", "%" + nome + "%") };
		return rowCount(Ator.class, filtros);
	}
}
